package com.wdf.project03.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wdf.project03.Mapper.EmpMapper;
import com.wdf.project03.pojo.Emp;
import com.wdf.project03.pojo.PageBean;
import com.wdf.project03.service.EempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EempService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public List<Emp> selectByQuery(String name, Short gender, LocalDate begin, LocalDate end) {
        return empMapper.list(name,gender,begin,end);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize);
        List<Emp> emps = empMapper.list(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) emps;
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public void deleteById(Integer id) {
        empMapper.deleteById(id);
    }

    @Override
    public void updateById(Emp emp) {
        empMapper.updateById(emp);
    }

    @Override
    public Emp selectById(Integer id) {
        return empMapper.selectById(id);
    }

    @Override
    public void insert(Emp emp) {
        emp.setPassword("123456");
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp selectCount(Emp emp) {
        return empMapper.selectCount(emp);
    }
}
